package edu.gatech.gui;

import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;

import edu.gatech.presenters.LoginPresenter;

public class LoginPanel extends JPanel{
	private static JTextField usernameField;
	private static int counter = 0;
	private JPasswordField passField;
	public LoginPanel(){
		
		JFrame login = new JFrame("Login Panel");
		JPanel loginPanel = new JPanel();
		
		login.getContentPane().add(loginPanel, BorderLayout.CENTER);
		loginPanel.setLayout(null);
			
		usernameField = new JTextField();
		usernameField.setFont(new Font("Arial", Font.PLAIN, 10));
		usernameField.setBounds(186, 183, 126, 20);
		loginPanel.add(usernameField);
		usernameField.setColumns(15);
		usernameField.setText("Username");
		usernameField.addMouseListener(new MouseAdapter() { 
	          public void mousePressed(MouseEvent me) { 
	            usernameField.setText(""); 
	          } 
	     }); 
		
		JButton btnLogin = new JButton("Login");
		btnLogin.setFont(new Font("Arial", Font.PLAIN, 10));
		btnLogin.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				LoginPresenter presenter = new LoginPresenter(usernameField.getText(), passField.getText());
				presenter.login();
			}
		});
		btnLogin.setBounds(322, 198, 74, 20);
		loginPanel.add(btnLogin); 
		loginPanel.getRootPane().setDefaultButton(btnLogin);
		
		passField = new JPasswordField();
		passField.setText("Password");
		passField.setBounds(186, 214, 126, 20);
		passField.addMouseListener(new MouseAdapter() { 
	          public void mousePressed(MouseEvent me) { 
	            passField.setText(""); 
	          } 
	     }); 
		loginPanel.add(passField);
		
		JPanel panel = new JPanel();
		panel.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null), "Login", TitledBorder.LEADING, TitledBorder.TOP, null, UIManager.getColor("Button.darkShadow")));
		panel.setBounds(171, 161, 239, 87);
		loginPanel.add(panel);
        
		MenuBar menuBar = new MenuBar(login);

        login.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        login.setSize(600,480);
        login.setTitle("Login Panel");
        login.setLocationRelativeTo(null); 
        login.setVisible(true);
	}
}
